<?php

namespace XWAM\Model;

/**
 * 附件上传设置 模型类
 *
 * @since 1.0 <2017-3-24> SoChishun <14507247@qq.com> Added.
 */
class UploadSettingModel extends AppbaseModel {

    protected $tableName = 't_porg_user_dict';

    /**
     * 保存单个配置
     * @return type
     */
    function saveConf() {
        $validator = array(
            array('title', 'require', '标题无效!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
            array('conf_group', 'require', '分组无效!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
            array('user_name', 'require', '用户无效!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
            array('site_id', 'number', 'SiteID无效!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
            array('status', 'number', '状态有误!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        );
        if (!$this->validate($validator)->create()) {
            return $this->returnMsg(false, $this->getError());
        }
        if (empty($this->id)) {
            unset($this->data['id']);
            $result = $this->add();
        } else {
            $result = $this->save();
        }
        return $this->returnMsg($result);
    }

    // 2017-3-24
    public function testContent($str) {
        $where = array('title' => 'SensitiveWords-Content', 'conf_group' => 'SensitiveWords');
        $data = $this->where($where)->getField('lcontent');
        $awords = explode(',', $data);
        $awords1 = array_combine($awords, array_fill(0, count($awords), '*'));
        $str = strtr($str, $awords1);
        return $str;
    }

}
